﻿Public Class frmClienteBuscador

    Private Sub frmClienteBuscador_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgCliente.AutoGenerateColumns = False
        CargarClientes()
    End Sub

    Private _codCliente As Integer = 0

    Public Property codCliente() As Integer
        Get
            Return _codCliente
        End Get
        Set(ByVal value As Integer)
            _codCliente = value
        End Set
    End Property

    Private _Cliente As String = ""

    Public Property ClienteDesc() As String
        Get
            Return _Cliente
        End Get
        Set(ByVal value As String)
            _Cliente = value
        End Set
    End Property

    Private _categoriaCliente As String = "precio1"

    Public Property ClienteCategoria() As String
        Get
            Return _categoriaCliente
        End Get
        Set(ByVal value As String)
            _categoriaCliente = value
        End Set
    End Property

    Dim controller As New ControllerSigeco.controller_ventas()

    Private Sub CargarClientes()

        Dim dt As New DataTable
        dt = controller.get_Clientes_All(oiml.dbConn, 0, txtProveedor.Text, txtruc.Text, True)
        dgCliente.DataSource = dt

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub seleccionar_Cliente()
        Try
            If dgCliente.SelectedRows.Count > 0 Then

                codCliente = dgCliente.SelectedRows(0).Cells(0).Value
                ClienteCategoria = dgCliente.SelectedRows(0).Cells(1).Value
                ClienteDesc = dgCliente.SelectedRows(0).Cells(2).Value
                Me.Close()

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarClientes()
    End Sub

    Private Sub txtProveedor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtProveedor.KeyDown, txtruc.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarClientes()

        End If
    End Sub

    Private Sub dgCliente_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgCliente.DoubleClick
        seleccionar_Cliente()
    End Sub

    Private Sub dgCliente_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgCliente.KeyDown
        If e.KeyCode = Keys.Enter Then
            seleccionar_Cliente()
        End If

    End Sub


End Class